﻿
var obj;
//取开始时间.
var startyear = 2010;
var startmonth = 6;
var startday = 23;
var starthour = 21;
var startmin = 58;
var startsec = 0;

//取服务器端现在时间.
var nowyear = 2010;
var nowmonth = 6;
var nowday = 23;
var nowhour = 21;
var nowmin = 57;
var nowsec = 50;

var nowtime;


//开始初始化。
function start(){
	var nowDate  = new Date(nowyear,nowmonth,nowday,nowhour,nowmin,nowsec);
	nowtime = nowDate.getTime();
	compDate();
}


//日期比较.
function compDate(){
	
	var timediv = document.getElementById("timeDown");

	var startDate = new Date(startyear,startmonth,startday,starthour,startmin,startsec);
	nowtime = nowtime + 1000;
	var starttime = startDate.getTime();
	
	var left=Math.floor((starttime-nowtime)/1000);
	if(left > 0){
		d=Math.floor(left/3600/24);
		h=Math.floor((left/3600)%24);
		m=Math.floor((left/60)%60);
		s=Math.floor(left%60);
		timediv.innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒";
	}else if(left==0){
		clearTimeout(obj);
		downTime(1);
	}else{
		//timediv.innerHTML = "已经结束";
		//clearTimeout(obj);
		
	}
	obj = setTimeout("compDate()",1000);
}

var startt;
var endt;
//开始后的倒计时.
function downTime(mincount){
	var start = new Date(startyear,startmonth,startday,starthour,startmin,startsec);
	startt=start.getTime();
	var end  = new Date(startyear,startmonth,startday,starthour,startmin+mincount,startsec);
	endt=end.getTime();
	

	down();
}


function down(){
	var timediv = document.getElementById("timeDown");
	startt =startt+1000;
	var diff = Math.floor((endt-startt)/1000);
	if(diff > 0){
		m=Math.floor((diff/60)%60);
		s=Math.floor(diff%60);
		timediv.innerHTML="剩余:"+m+"分"+s+"秒";
	}else if(diff==0){
		timediv.innerHTML="拍卖结束";
		clearTimeout(obj);
	}else{

	}
	obj = setTimeout("down()",1000);
}